﻿@implements IDisposable

@inject IUserStatusService userStatusService
@inject ApplicationStateService appState
@inject ClientUIStateService uiState

<div class="statusbar">
    <TimedStatus DisplayIntervalSecs="30" StatusText="@StatusText"/>
    <WorkStatus/>

    @if( ! uiState.IsSmallScreenDevice )
    {
        <ConnectionStatus/>

        @if ( appState.IsWebAssembly )
        {
            <LoginDisplayWasm/>
        }
        else
        {
            <LoginDisplay/>
        }

        <Toolbar/>
    }
</div>

@code
{
    private string StatusText { get; set; }

    private void UpdateStatus(string newText)
    {
        if ( StatusText != newText )
        {
            StatusText = newText;
            StateHasChanged();
        }
    }

    protected override void OnAfterRender(bool firstRender)
    {
        if ( firstRender )
        {
            userStatusService.OnStatusChanged += UpdateStatus;
        }
    }

    public void Dispose()
    {
        userStatusService.OnStatusChanged -= UpdateStatus;
    }

}